<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" id="i1">
<input type="button" value="平方" onclick="f1()">
<div>结果:<span></span></div>

<script>
    function f1(){
        let i = document.querySelector("#i1");
        let d = document.querySelector("span");
        /*isNaN(x) 判断变量是否是数*/
        if(isNaN(i.value)){
            d.innerText="输入错误！";
            return;
        }
        //当两个字符串进行-*/运算时会自动转成数值，进行+运算时拼接
        // s.innerText=i.value*1+i.value*1;
        /*parseInt() 转成数 正常情况下是字符串拼接 所以加减的时候进行转换*/
        //parseFloat()将字符串转成整数或者小数
        d.innerText = parseInt(i.value)+parseInt(i.value);

    }
</script>
</body>
</html>